package com.itheima.service;

import com.itheima.mapper.UserMapper;
import com.itheima.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;


public class UserService {

    private UserMapper userMapper;

    String resource = "mybatis-config.xml";
    InputStream inputStream = null;

    {
        try {
            inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            UserMapper mapper = sqlSessionFactory.openSession().getMapper(UserMapper.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public User findById(long id){
        return userMapper.findById(id);
    }

    public List<User> findAll(){
        return userMapper.findAll();
    }
}
